let image, num, symbol

let fail=true
while(fail){
    image=prompt("Please input the image you want to create. (triangle, square, or diamond)")
    symbol=prompt("Please input the symbol you want to use to create the image. (No space can be used)")
    num=prompt("Please input the length of the image. (No 0 is allowed.)")
    if(symbol==" " || num==0 || (image!="triangle" && image!="square" && image!="diamond")){
        alert("Your input is incorrect. Please try again.")
    }else{
        fail=false
    }
}
        

if(image=="triangle"){
    let message = ""
    let m,n
    for(m=1;m<=num;m++){
        for(n=0;n<m;n++){
            message+=symbol
        }
        message+="\n"
    }
    alert(message)
}else if(image=="square"){
    let message = ""
    let i,j
    for(i=0;i<num;i++){
        for(j=0;j<num;j++){
            message+=symbol
        }
        message+="\n"
    }
    alert(message)
}else if(image=="diamond"){
    let message=""
    let p,q
    for(p=1;p<num;p++){
        for(q=0;q<(num-p);q++){
            message+=" "
        }
        for(q=0;q<(p*2-1);q++){
            message+=symbol
        }
        for(q=0;q<(num-p);q++){
            message+=" "
        }
        message+="\n"
    }
    for(q=0;q<(num*2-1);q++){
        message+=symbol
    }
    message+="\n"
    for(p=1;p<num;p++){
        for(q=0;q<p;q++){
            message+=" "
        }
        for(q=0;q<(num*2-1-p*2);q++){
            message+=symbol
        }
        for(q=0;q<p;q++){
            message+=" "
        }
        message+="\n"
    }
    alert(message)
}
